import { saveBatchOrder } from '@/services/ant-design-pro/api';
import { useRequest } from '@@/exports';
import { PlusOutlined } from '@ant-design/icons';
import { ModalForm, ProFormText } from '@ant-design/pro-components';
import { Button, message } from 'antd';
import { FC } from 'react';

interface CreateFormProps {
  reload: () => void;
  onConfirm: (values: any) => void;
}

const CreateForm: FC<CreateFormProps> = (props) => {
  const [messageApi, contextHolder] = message.useMessage();
  const { reload } = props;
  const { run } = useRequest(saveBatchOrder, {
    manual: true,
    onSuccess: () => {
      reload();
      messageApi.success('添加成功');
    },
    onError: (error) => {
      messageApi.error(error.message);
    },
  });
  return (
    <>
      {contextHolder}
      <ModalForm
        onFinish={async (value) => {
          await run({ ...value } as API.BatchOrder);
          return true;
        }}
        title={"创建订单"}
        trigger={
          <Button type="primary" icon={<PlusOutlined />}>
            创建订单
          </Button>
        }
      >
        <ProFormText
          rules={[
            {
              required: true,
              message: '请输入公司名称',
            },
          ]}
          placeholder="请输入公司名称"
          width="md"
          name="companyName"
        />
        <ProFormText
          rules={[
            {
              required: true,
              message: '请输入联系人',
            },
          ]}
          placeholder="请输入联系人"
          width="md"
          name="contactNo"
        />
        <ProFormText placeholder="请输入备注" width="md" name="remark" />
      </ModalForm>
    </>
  );
};
export default CreateForm;
